<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for src/utils/monitorKeyboard.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="..\..\prettify.css" />
    <link rel="stylesheet" href="..\..\base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(..\..\sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="..\..\index.html">All files</a> / <a href="index.html">src/utils</a> monitorKeyboard.js
    </h1>
    <div class='clearfix'>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">/**
 * @class 监听虚拟键盘
 * @classdesc 监听虚拟键盘弹出隐藏
 * @public onEnd 结束监听虚拟键盘
 * @public onShow 传递一个回调 监听虚拟键盘弹出
 * @public onHidden 传递一个回调 监听虚拟键盘隐藏
 */
class MonitorKeyboard {
  constructor() <span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >    this.type = this.IsIA();</span>
<span class="cstat-no" title="statement not covered" >    this.originalHeight = window.innerHeight;</span>
  }
 
  /**
   *  @function IsIA 获取设备类型
   *  @param  1 Android 2 iOS  
   */
  IsIA = <span class="fstat-no" title="function not covered" >() =&gt; </span>{
    const userAgent = <span class="cstat-no" title="statement not covered" >typeof window === 'object' ? window.navigator.userAgent : '';</span>
<span class="cstat-no" title="statement not covered" >    if (/android/i.test(userAgent)) {</span>
<span class="cstat-no" title="statement not covered" >      return 1; </span>
    } else <span class="cstat-no" title="statement not covered" >if (/iPhone|iPod|iPad/i.test(userAgent)) {</span>
<span class="cstat-no" title="statement not covered" >      return 2; </span>
    }
  }
&nbsp;
  // Android系统
  onResize = <span class="fstat-no" title="function not covered" >() =&gt; </span>{
    //键盘弹起与隐藏都会引起窗口的高度发生变化
    const resizeHeight = <span class="cstat-no" title="statement not covered" >window.innerHeight;</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >    if (this.originalHeight - resizeHeight &gt; 50) {</span>
<span class="cstat-no" title="statement not covered" >      this.show('Android系统: 软键盘弹出');</span>
    } else {
<span class="cstat-no" title="statement not covered" >      this.hidden('Android系统: 软键盘收起');</span>
    }
  }
&nbsp;
  // iOS获取焦点
  onFocusin = <span class="fstat-no" title="function not covered" >() =&gt; </span>{
<span class="cstat-no" title="statement not covered" >    this.show('iOS系统:软键盘弹出');</span>
  }
 
  // iOS失去焦点
  onFocusout = <span class="fstat-no" title="function not covered" >() =&gt; </span>{
<span class="cstat-no" title="statement not covered" >    this.hidden('iOS系统:软键盘收起');</span>
  }
&nbsp;
  /**  
   * @function onStart 开始监听虚拟键盘  
   */
  onStart = <span class="fstat-no" title="function not covered" >() =&gt; </span>{
<span class="cstat-no" title="statement not covered" >    if (this.type == 1) {</span>
      // 获取窗口的高度
<span class="cstat-no" title="statement not covered" >      window.addEventListener('resize', this.onResize);</span>
    }
<span class="cstat-no" title="statement not covered" >    if (this.type == 2) {</span>
      // iOS系统
<span class="cstat-no" title="statement not covered" >      window.addEventListener('focusin', this.onFocusin);</span>
<span class="cstat-no" title="statement not covered" >      window.addEventListener('focusout', this.onFocusout);</span>
    }
  }
 
  /** 
   * @function onEnd 结束监听虚拟键盘  
   */
  onEnd = <span class="fstat-no" title="function not covered" >() =&gt; </span>{
<span class="cstat-no" title="statement not covered" >    if (this.type == 1) {</span>
      //获取窗口的高度
<span class="cstat-no" title="statement not covered" >      window.removeEventListener('resize', this.onResize);</span>
    }
<span class="cstat-no" title="statement not covered" >    if (this.type == 2) {</span>
<span class="cstat-no" title="statement not covered" >      window.removeEventListener('focusin', this.onFocusin);</span>
<span class="cstat-no" title="statement not covered" >      window.removeEventListener('focusout', this.onFocusout);</span>
    }
  }
 
  /**
   * @function  onShow 传递一个回调函数
   * @param  虚拟键盘弹出时触发
   */
  onShow = <span class="fstat-no" title="function not covered" >(</span>fn) =&gt; {
<span class="cstat-no" title="statement not covered" >    this.show = fn;</span>
  }
   
  /**
    * @function  onHidden 传递一个回调函数
    * @param  虚拟键盘隐藏时触发
    */
  onHidden = <span class="fstat-no" title="function not covered" >(</span>fn) =&gt; {
<span class="cstat-no" title="statement not covered" >    this.hidden = fn;</span>
  }
}
 
export default MonitorKeyboard
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Nov 27 2023 23:16:11 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="..\..\prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="..\..\sorter.js"></script>
</body>
</html>
